package com.oragraph.data.group;

import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.Vector;

public class GroupTypeManager {
	
	private static Hashtable<String,Vector<GroupFactory>> _groupFactories;
	
	static {
		_groupFactories=new Hashtable<String,Vector<GroupFactory>>();
	}
	
	public static void registerGroupFactory(String toInstanceType, GroupFactory factory) {
		Vector<GroupFactory> factories=_groupFactories.get(toInstanceType);
		if (factories==null) {
			factories=new Vector<GroupFactory>();
			_groupFactories.put(toInstanceType, factories);
		}
		factories.add(factory);
	}
	
	public static Vector<GroupFactory> getGroupFactories(String toInstanceType) {
		return _groupFactories.get(toInstanceType);
	}
	
	public static Vector<GroupFactory> getGroupFactories(String toInstanceType, String filterString) {
		
		Vector<GroupFactory> registered=_groupFactories.get(toInstanceType);
		Vector<GroupFactory> result=new Vector<GroupFactory>();
		
		if (registered==null) return result; // cannot expand such nodes
		
		for (int i=0; i<registered.size(); i++) {
			String byType=registered.elementAt(i).getName();
			StringTokenizer st=new StringTokenizer(filterString, ";");
			boolean filtered=false;
			while (st.hasMoreTokens()) {
				String token=st.nextToken();
				if (token.equals(byType)) {
					filtered=true;
					break;
				}
			}
			if (!filtered) result.add(registered.elementAt(i));
		}
		return result;
	}
	
	

}
